package com.mxfcode.front.bbs_answer_questions.service.impl;


import com.mxfcode.entity.BBSAnswerQuestions;
import com.mxfcode.front.bbs_answer_questions.mapper.AnswerQuestionsMapper;
import com.mxfcode.front.bbs_answer_questions.service.AnswerQuestionsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AnswerQuestionsServiceImpl implements AnswerQuestionsService {

    private static final Logger logger = LoggerFactory.getLogger(AnswerQuestionsServiceImpl.class);

    @Resource
    private AnswerQuestionsMapper answerQuestionsMapper;

    @Override
    public int selectAnswerQuestionsRows(String type) {
        return answerQuestionsMapper.selectAnswerQuestionsRows(type);
    }

    @Override
    public List<BBSAnswerQuestions> selectAnswerQuestionsList(String type, int offset, int limit, int i) {
        //type == 0 搜索全部，type == 1，按点赞排序，type == 2,按回答人数排序，type == 3 按创建时间排序
        type = Integer.valueOf(type) == 0 ? null : (Integer.valueOf(type) == 1 ? "likes_count" :
                (Integer.valueOf(type) == 2 ? "comment_count" : (Integer.valueOf(type) == 3 ? "create_date" : null)));
        return answerQuestionsMapper.selectAnswerQuestionsList(type,offset,limit,i);
    }

    @Override
    public BBSAnswerQuestions selectMessageById(String messageId) {
        return answerQuestionsMapper.selectMessageById(messageId);
    }
}
